package Operation;

import User.User;
import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOpereatin implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("增加书籍");
        if(bookList.getBooknum() == 10){
            System.out.println("书架已经满了，无法增加书籍");
            return;
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入书名:");
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getBooknum(); i++) {
            if (name.equals(bookList.getBooks()[i].getName())) {
                System.out.println("已经有这本书了！");
                return;
            }
        }
        System.out.println("请输入种类:");
        String type = scanner.nextLine();
        System.out.println("请输入书价:");
        int price = scanner.nextInt();
        scanner.nextLine();
        System.out.println("请输入作者:");
        String author = scanner.nextLine();
        Book book1 = new Book(name,type,price,author);
        bookList.setBooks(bookList.getBooknum(), book1);
        System.out.println("增加书籍" + name + "完成");
        bookList.setBooknum(bookList.getBooknum() + 1);
    }


}
